using System;
using System.Collections;
using System.Data;
using CE.Database;
/// <summary>
/// Summary description for UserProfileDB
/// </summary>
/// 
namespace CE.Provider
{
    public class HFVariableInfoDB
    {
        public HFVariableInfoDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(HFVariableInfo hfvarinfo)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocHFVariableInfoInsertUpdateSingleItem]";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@HFVariableId", hfvarinfo.HFVariableId);
            _sPara.Add("@HFProviderId", hfvarinfo.HFProviderId);
            _sPara.Add("@ProductName", hfvarinfo.ProductName);
            _sPara.Add("@LoanPurpose", hfvarinfo.LoanPurpose);
            _sPara.Add("@PropertyType", hfvarinfo.PropertyType);
            _sPara.Add("@InterestRateType", hfvarinfo.InterestRateType);
            _sPara.Add("@MinLoanTenure", hfvarinfo.MinLoanTenure);
            _sPara.Add("@MaxLoanTenure", hfvarinfo.MaxLoanTenure);
            _sPara.Add("@MinAgeApplicant", hfvarinfo.MinAgeApplicant);
            _sPara.Add("@MaxAgeApplicant", hfvarinfo.MaxAgeApplicant);
            _sPara.Add("@MaxMarginFin", hfvarinfo.MaxMarginFin);
            _sPara.Add("@LockInPeriod", hfvarinfo.LockInPeriod);
            _sPara.Add("@FullRedPen", hfvarinfo.FullRedPen);
            _sPara.Add("@MinPartialRepay", hfvarinfo.MinPartialRepay);
            _sPara.Add("@MaxPartialRepay", hfvarinfo.MaxPartialRepay);
            _sPara.Add("@HomeFireIns", hfvarinfo.HomeFireIns);
            _sPara.Add("@LegalFeeSubsidy", hfvarinfo.LegalFeeSubsidy);
            _sPara.Add("@RequireMRTA", hfvarinfo.RequireMRTA);

            _sPara.Add("@InterestY1", hfvarinfo.InterestY1);
            _sPara.Add("@Y1Sibor", hfvarinfo.Y1Sibor);
            _sPara.Add("@Y1SiborSign", hfvarinfo.Y1SiborSign);

            _sPara.Add("@InterestY2", hfvarinfo.InterestY2);
            _sPara.Add("@Y2Sibor", hfvarinfo.Y2Sibor);
            _sPara.Add("@Y2SiborSign", hfvarinfo.Y2SiborSign);

            _sPara.Add("@InterestY3", hfvarinfo.InterestY3);
            _sPara.Add("@Y3Sibor", hfvarinfo.Y3Sibor);
            _sPara.Add("@Y3SiborSign", hfvarinfo.Y3SiborSign);

            _sPara.Add("@InterestY4", hfvarinfo.InterestY4);
            _sPara.Add("@Y4Sibor", hfvarinfo.Y4Sibor);
            _sPara.Add("@Y4SiborSign", hfvarinfo.Y4SiborSign);

            _sPara.Add("@InterestY5", hfvarinfo.InterestY5);
            _sPara.Add("@Y5Sibor", hfvarinfo.Y5Sibor);
            _sPara.Add("@Y5SiborSign", hfvarinfo.Y5SiborSign);

            _sPara.Add("@InterestThereAfter", hfvarinfo.InterestThereAfter);
            _sPara.Add("@TASibor", hfvarinfo.TASibor);
            _sPara.Add("@TASiborSign", hfvarinfo.TASiborSign);

            _sPara.Add("@Status", hfvarinfo.Status);
            _sPara.Add("@RefCEUserId", hfvarinfo.RefCEUserId);
            _sPara.Add("@Info1", hfvarinfo.Info1);
            _sPara.Add("@Info2", hfvarinfo.Info2);
            _sPara.Add("@Info3", hfvarinfo.Info3);
            _sPara.Add("@Info4", hfvarinfo.Info4);
            _sPara.Add("@Info5", hfvarinfo.Info5);
            _sPara.Add("@Info6", hfvarinfo.Info6);
            _sPara.Add("@Info7", hfvarinfo.Info7);
            _sPara.Add("@Info8", hfvarinfo.Info8);
            _sPara.Add("@Info9", hfvarinfo.Info9);
            _sPara.Add("@Info10", hfvarinfo.Info10);
            _sPara.Add("@NInfo11", hfvarinfo.NInfo11);
            _sPara.Add("@NInfo12", hfvarinfo.NInfo12);
            _sPara.Add("@NInfo13", hfvarinfo.NInfo13);
            _sPara.Add("@NInfo14", hfvarinfo.NInfo14);
            _sPara.Add("@NInfo15", hfvarinfo.NInfo15);
            _sPara.Add("@NInfo16", hfvarinfo.NInfo16);
            _sPara.Add("@NInfo17", hfvarinfo.NInfo17);
            _sPara.Add("@NInfo18", hfvarinfo.NInfo18);
            _sPara.Add("@NInfo19", hfvarinfo.NInfo19);
            _sPara.Add("@NInfo20", hfvarinfo.NInfo20);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public bool Update()
        {
            return true;
        }

        public bool Delete()
        {
            return true;
        }

        public HFVariableInfo GetVariableInfo(Int64 HFID)
        {
            MyDatabase _Db = new MyDatabase();
            string _spName = "[sprocHFVariableSelectSingleItem]";
            HFVariableInfo _result = null;
            DataTable _dt;
            SortedList _sPara = new SortedList();

            _sPara.Add("@HFVariableID", HFID);

            _dt = _Db.GetDataTableBySP(_spName, _sPara);

            if (_dt != null && _dt.Rows.Count > 0)
            {
                _result = new HFVariableInfo();
                _result = FillDataRecord(_dt);
            }

            return _result;
        }

        private HFVariableInfo FillDataRecord(DataTable myDataTable)
        {
            HFVariableInfo myVariable = new HFVariableInfo();
            myVariable.HFVariableId = Convert.ToInt64(myDataTable.Rows[0]["HFVariableId"].ToString());
            myVariable.HFProviderId = Convert.ToInt64(myDataTable.Rows[0]["HFProviderId"].ToString());
            myVariable.ProductName = myDataTable.Rows[0]["ProductName"].ToString();
            myVariable.PropertyType = Convert.ToInt16(myDataTable.Rows[0]["PropertyType"].ToString());
            myVariable.LoanPurpose = Convert.ToInt16(myDataTable.Rows[0]["LoanPurpose"].ToString());
            myVariable.InterestRateType = Convert.ToInt16(myDataTable.Rows[0]["InterestRateType"].ToString());
            myVariable.MinLoanTenure = Convert.ToInt32(myDataTable.Rows[0]["MinLoanTenure"].ToString());
            myVariable.MaxLoanTenure = Convert.ToInt32(myDataTable.Rows[0]["MaxLoanTenure"].ToString());
            myVariable.MinAgeApplicant = Convert.ToInt32(myDataTable.Rows[0]["MinAgeApplicant"].ToString());
            myVariable.MaxAgeApplicant = Convert.ToInt32(myDataTable.Rows[0]["MaxAgeApplicant"].ToString());
            myVariable.MaxMarginFin = Convert.ToInt32(myDataTable.Rows[0]["MaxMarginFin"].ToString());
            myVariable.LockInPeriod = Convert.ToInt32(myDataTable.Rows[0]["LockInPeriod"].ToString());
            myVariable.FullRedPen = myDataTable.Rows[0]["FullRedPen"].ToString();
            myVariable.MinPartialRepay = Convert.ToSingle(myDataTable.Rows[0]["MinPartialRepay"].ToString());
            myVariable.MaxPartialRepay = Convert.ToSingle(myDataTable.Rows[0]["MinPartialRepay"].ToString());
            myVariable.HomeFireIns = myDataTable.Rows[0]["HomeFireIns"].ToString();
            myVariable.LegalFeeSubsidy = myDataTable.Rows[0]["LegalFeeSubsidy"].ToString();
            myVariable.RequireMRTA = Convert.ToBoolean(myDataTable.Rows[0]["RequireMRTA"].ToString());
            myVariable.InterestY1 = Convert.ToSingle(myDataTable.Rows[0]["InterestY1"].ToString());
            myVariable.Y1Sibor = Convert.ToInt32(myDataTable.Rows[0]["Y1Sibor"].ToString());
            myVariable.Y1SiborSign = Convert.ToChar(myDataTable.Rows[0]["Y1SiborSign"].ToString());
            myVariable.InterestY2 = Convert.ToSingle(myDataTable.Rows[0]["InterestY2"].ToString());
            myVariable.Y2Sibor = Convert.ToInt32(myDataTable.Rows[0]["Y2Sibor"].ToString());
            myVariable.Y2SiborSign = Convert.ToChar(myDataTable.Rows[0]["Y2SiborSign"].ToString());
            myVariable.InterestY3 = Convert.ToSingle(myDataTable.Rows[0]["InterestY3"].ToString());
            myVariable.Y3SiborSign = Convert.ToChar(myDataTable.Rows[0]["Y3SiborSign"].ToString());
            myVariable.Y3Sibor = Convert.ToInt32(myDataTable.Rows[0]["Y3Sibor"].ToString());
            myVariable.InterestY4 = Convert.ToSingle(myDataTable.Rows[0]["InterestY4"].ToString());
            myVariable.Y4Sibor = Convert.ToInt32(myDataTable.Rows[0]["Y4Sibor"].ToString());
            myVariable.Y4SiborSign = Convert.ToChar(myDataTable.Rows[0]["Y4SiborSign"].ToString());
            myVariable.InterestY5 = Convert.ToSingle(myDataTable.Rows[0]["InterestY5"].ToString());
            myVariable.Y5Sibor = Convert.ToInt32(myDataTable.Rows[0]["Y5Sibor"].ToString());
            myVariable.Y5SiborSign = Convert.ToChar(myDataTable.Rows[0]["Y5SiborSign"].ToString());
            myVariable.InterestThereAfter = Convert.ToSingle(myDataTable.Rows[0]["InterestThereAfter"].ToString());
            myVariable.TASibor = Convert.ToInt32(myDataTable.Rows[0]["TASibor"].ToString());
            myVariable.TASiborSign = Convert.ToChar(myDataTable.Rows[0]["TASiborSign"].ToString());
            myVariable.Status = Convert.ToBoolean(myDataTable.Rows[0]["Status"].ToString());
            return myVariable;
        }

    }
}